//
// Created by Jisam on 2024年11月15日23:31:58.
// Solution of  A. Penchick and Modern Monument
#include <bits/stdc++.h>

#define  int long long
#define  endl "\n"
#define  all(x) (x).begin(),(x).end()
#define  pb push_back
using namespace std;

void solve(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0 ; i < n ; i ++){
        cin >> a[i];
    }
    map<int,int> freq;
    int mx = 0;
    for(int x : a){
        freq[x] += 1;
        mx = max(mx,freq[x]);
    }
    cout << n - mx << endl;
}
signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int _ = 1;
    cin >> _;
    while(_ --){
        solve();
    }
    return 0;
}